package com.mycompany.myapp.service.dto;
import com.mycompany.myapp.domain.Authority;
import com.mycompany.myapp.domain.SUser;

import java.time.ZonedDateTime;
import java.io.Serializable;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * A DTO for the {@link com.mycompany.myapp.domain.SUser} entity.
 */
public class SUserInfoDTO implements Serializable {

    private Long id;

    private String username;

    private String password;

    private String avatar;

    private String email;

    private String phone;

    private Boolean isActive;

    private ZonedDateTime createTime;

    private ZonedDateTime updateTime;

    private Set<String> authorities;

    public SUserInfoDTO(SUser sUser){
        this.id = sUser.getId();
        this.avatar = sUser.getAvatar();
        this.username = sUser.getUsername();
        this.email = sUser.getEmail();
        this.password = sUser.getPassword();
        this.phone = sUser.getPhone();
        this.isActive = sUser.getIsActive();
        this.createTime = sUser.getCreateTime();
        this.updateTime = sUser.getUpdateTime();
        this.authorities = sUser.getAuthorities().stream()
            .map(Authority::getName)
            .collect(Collectors.toSet());;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public Boolean isIsActive() {
        return isActive;
    }

    public void setIsActive(Boolean isActive) {
        this.isActive = isActive;
    }

    public ZonedDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(ZonedDateTime createTime) {
        this.createTime = createTime;
    }

    public ZonedDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(ZonedDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public Set<String> getAuthorities() {
        return authorities;
    }

    public void setAuthorities(Set<String> authorities) {
        this.authorities = authorities;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        SUserDTO sUserDTO = (SUserDTO) o;
        if (sUserDTO.getId() == null || getId() == null) {
            return false;
        }
        return Objects.equals(getId(), sUserDTO.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getId());
    }

    @Override
    public String toString() {
        return "SUserDTO{" +
            "id=" + getId() +
            ", username='" + getUsername() + "'" +
            ", avatar='" + getAvatar() + "'" +
            ", email='" + getEmail() + "'" +
            ", phone='" + getPhone() + "'" +
            ", isActive='" + isIsActive() + "'" +
            ", createTime='" + getCreateTime() + "'" +
            ", updateTime='" + getUpdateTime() + "'" +
            ", authorities=" + getAuthorities() +
            "}";
    }
}
